/*
Copyright (C) 2010- Peter Bui and Aaron Dingler.
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

#include "smq_common.h"
#include "smq_util.h"

#include <int_sizes.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>

INT64_T
smq_util_get_file_size(const char *path)
{
    struct stat file_stats;

    if (stat(path, &file_stats) < 0)
	return -1;
    else
	return file_stats.st_size;
}

int
smq_util_file_exists(const char *path)
{
    struct stat file_stats;

    if (stat(path, &file_stats) < 0)
	return 0;
    else
	return 1;
}
    
static char SMQ_UTIL_ID[SMQ_LINE_MAX];

const char *
smq_util_get_unique_identifier(void)
{
    struct timeval t;

    gettimeofday(&t, NULL);

    snprintf(SMQ_UTIL_ID, SMQ_LINE_MAX, "%ld.%06ld", t.tv_sec, t.tv_usec);

    return SMQ_UTIL_ID;
}

/* 
vim: sw=4 sts=4 ts=8 ft=cpp
*/
